package at.codejedi.sto.gui;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import at.codejedi.sto.config.Configuration;

public class AboutDialog extends JDialog {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4004910870731386222L;

	public AboutDialog() {
		setTitle("About STO Combat Anaylser");
		getContentPane().setLayout(
				new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

		JLabel lblNewLabel_2 = new JLabel("");
		lblNewLabel_2.setAlignmentX(Component.CENTER_ALIGNMENT);

		Icon icon = Configuration.getFullIcon();

		double scale = 0.2;

		BufferedImage bi = new BufferedImage(
				(int) (scale * icon.getIconWidth()),
				(int) (scale * icon.getIconHeight()),
				BufferedImage.TYPE_INT_ARGB);
		Graphics2D g = bi.createGraphics();
		g.scale(scale, scale);
		icon.paintIcon(null, g, 0, 0);
		g.dispose();

		Component verticalStrut_4 = Box.createVerticalStrut(20);
		getContentPane().add(verticalStrut_4);

		lblNewLabel_2.setIcon(new ImageIcon(bi));
		getContentPane().add(lblNewLabel_2);

		getContentPane().add(Box.createRigidArea(new Dimension(0, 10)));

		JLabel name = new JLabel("STO Combat Analyser\r\n");
		name.setFont(new Font("Lucida Grande", Font.PLAIN, 18));

		name.setAlignmentX(0.5f);
		getContentPane().add(name);

		Component verticalStrut = Box.createVerticalStrut(20);
		getContentPane().add(verticalStrut);

		JLabel lblNewLabel = new JLabel(
				"http://code.google.com/p/sto-combat-analyser/");
		lblNewLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
		getContentPane().add(lblNewLabel);

		JButton close = new JButton("Close");
		close.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent event) {
				dispose();
			}
		});

		Component verticalStrut_1 = Box.createVerticalStrut(20);
		getContentPane().add(verticalStrut_1);

		JLabel lblNewLabel_1 = new JLabel(
				"<html>Please help improving this analyser by <ul><li>reporting all problems</li><li>submitting new ideas</li></ul></html>Thank you!");
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_1.setAlignmentX(Component.CENTER_ALIGNMENT);
		getContentPane().add(lblNewLabel_1);

		Component verticalStrut_2 = Box.createVerticalStrut(20);
		getContentPane().add(verticalStrut_2);

		JLabel lblJimhawkAtLbwikipedia = new JLabel(
				"<html><body>Icon Design:<br/>JimHawk at lb.wikipedia <a href=\"http://www.gnu.org/copyleft/fdl.html\">GFDL</a> or <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\">CC-BY-SA-3.0</a><br/>via Wikimedia Commons</body></html>");
		lblJimhawkAtLbwikipedia.setAlignmentX(Component.CENTER_ALIGNMENT);
		lblJimhawkAtLbwikipedia.setHorizontalAlignment(SwingConstants.CENTER);
		getContentPane().add(lblJimhawkAtLbwikipedia);

		Component verticalStrut_3 = Box.createVerticalStrut(20);
		getContentPane().add(verticalStrut_3);

		close.setAlignmentX(Component.CENTER_ALIGNMENT);
		getContentPane().add(close);
		setModalityType(ModalityType.APPLICATION_MODAL);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setSize(450, 460);
	}

}
